package com.agile.major.service.impl;

import com.agile.major.domain.BaseMajor;
import com.agile.major.domain.MajorQcbook;
import com.agile.major.repository.BaseMajorRepository;
import com.agile.major.repository.MajorQcbookRepository;
import com.agile.major.service.MajorQcbookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing MajorQcbook.
 */
@Service
@Transactional
public class MajorQcbookServiceImpl implements MajorQcbookService{

    private final Logger log = LoggerFactory.getLogger(MajorQcbookServiceImpl.class);

    private final MajorQcbookRepository majorQcbookRepository;
    private BaseMajorRepository baseMajorRepository;

    public MajorQcbookServiceImpl(
        MajorQcbookRepository majorQcbookRepository,
        BaseMajorRepository baseMajorRepository
    ) {
        this.majorQcbookRepository = majorQcbookRepository;
        this.baseMajorRepository=baseMajorRepository;
    }

    /**
     * Save a majorQcbook.
     *
     * @param majorQcbook the entity to save
     * @return the persisted entity
     */
    @Override
    public MajorQcbook save(MajorQcbook majorQcbook) {
        log.debug("Request to save MajorQcbook : {}", majorQcbook);
        return majorQcbookRepository.save(majorQcbook);
    }

    /**
     *  Get all the majorQcbooks.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<MajorQcbook> findAll(Pageable pageable) {
        log.debug("Request to get all MajorQcbooks");
        return majorQcbookRepository.findAll(pageable);
    }

    /**
     *  Get one majorQcbook by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public MajorQcbook findOne(Long id) {
        log.debug("Request to get MajorQcbook : {}", id);
        return majorQcbookRepository.findOne(id);
    }

    /**
     *  Delete the  majorQcbook by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete MajorQcbook : {}", id);
        majorQcbookRepository.delete(id);
    }

    @Override
    public Page<MajorQcbook> getQcBookByMajor(Long id, Pageable pageable) {
        BaseMajor major = baseMajorRepository.findOne(id);
        if (major == null) {
            log.debug("Request to get RecruitStudent : {}", major);
        }
        return majorQcbookRepository.findMajorQcbookByBaseMajor(major,pageable);
    }


}
